package com.caiju.health.controller;


import com.caiju.health.constant.MessageConstant;
import com.caiju.health.entity.PageResult;
import com.caiju.health.entity.Result;
import com.caiju.health.pojo.CheckItem;
import com.caiju.health.pojo.User;
import com.caiju.health.service.ICheackItemService;
import com.caiju.health.service.IUserService;
import com.caiju.health.vo.QueryPageBean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin    //允许跨域，因为不同端口号，认为不是同一个人
public class UserController {
    @Resource
    private IUserService userService;
    //    find数据
    @PostMapping("/findUser")
    public Result findUser(@RequestBody User user){
        System.out.println("username="+user.getUsername());
        System.out.println("password="+user.getPassword());
        User user1 =  userService.findUser(user);
        if (user1 == null){
            return null;
        }
        //表示需要返回一个Result对象，给前端做响应
        return  new Result(true, MessageConstant.LOGIN_SUCCESS,user1);
    }
    //    新增user
    @PostMapping("/addUser")
    public Result addUser(@RequestBody User user){
        System.out.println("username="+user.getUsername());
        System.out.println("password="+user.getPassword());
        user.setStation("1");
        userService.addUser(user);
        //表示需要返回一个Result对象，给前端做响应
        return  new Result(true, MessageConstant.LOGIN_SUCCESS);
    }
    //    更新用户数据
    @PostMapping("/updateUser")
    public Result updateUser(@RequestBody User user){
        System.out.println("username="+user.getUsername());
        System.out.println("password="+user.getPassword());
        userService.updateUser(user);
        //表示需要返回一个Result对象，给前端做响应
        return  new Result(true, MessageConstant.LOGIN_SUCCESS);
    }



}
